/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package action;

import db.AccountObj;
import form.AccountForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.Account;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author Administrator
 */
public class AccountAction extends Action {

    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        AccountForm accfrm = (AccountForm) form;
        Account acc = new Account(accfrm.getAccNo(), accfrm.getPass(), accfrm.getBalance());
        AccountObj obj = new AccountObj();
        if (!accfrm.getRepass().equals(acc.getPassword())) {
            request.setAttribute("error", "Password not compare");
            return mapping.findForward("doagain");
        } else {
            if (obj.InsertAcc(acc) > 0) {
                request.setAttribute("error", "insert success");
                return mapping.findForward("showAll");
            } else {
                request.setAttribute("error", "insert fail");
                return mapping.findForward("doagain");
            }
        }

        //request.setAttribute("acc", accfrm.getAccNo());

    }
}
